﻿@model equinoxWeb.Models.Facturacion
@{
    ViewBag.Title = "Edicion de costos";
    Layout = (ViewBag.esCliente!=null && ViewBag.esCliente?"~/Views/Shared/_ClienteLayout.cshtml":"~/Views/Shared/_Layout.cshtml");
}
@using equinoxWeb.Models;
<!-- content -->
<script type='text/javascript' src="/scripts/costDocument.js"></script>
<script>
    $(function () {
        $(".customDate").datepicker();
        $(".customTime").timepicker({
            defaultTime: false,
            minuteStep: 5,
            showMeridian: false,
            disableFocus: true
        });

    });
</script>
<form class="form-horizontal" name="editForm" method="post">
    <fieldset>
        <legend>Registrar costos</legend>
        <input type="hidden" name="IdCaso" id="IdCaso" value="@ViewBag.idCaso" />
    </fieldset>
    

    <div class="form-group">
        <label class="col-md-4 col-sm-6 control-label" for="Facturara">Facturar a:</label>
        <div class="col-md-3 col-sm-6">
            @Html.TextAreaFor(model => model.Facturara, new { @class = "form-control"})
            <span style="color:white"> (Si se deja en blanco se usará el nombre del cliente)</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-4 col-sm-6 control-label" for="Rate">Costo por hora:</label>
        <div class="col-md-3 col-sm-6">
            @Html.TextBoxFor(model => model.Rate, new { @class = "form-control",@onblur="javascript:actualizar()", @onkeydown="javascript:validateNumber(event)"})
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-4 col-sm-6 control-label" for="Expenses">Gastos:</label>
        <div class="col-md-3 col-sm-6">
            @Html.TextBoxFor(model => model.Expenses, new { @class = "form-control", @onkeydown="javascript:validateNumber(event)"})
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-4 col-sm-6 control-label" for="Moneda">Moneda:</label>
        <div class="col-md-3 col-sm-6">
            <select name="IdMoneda" class="form-control">
                @foreach (Moneda moneda in ViewBag.listaMoneda)
                {
                    <option value="@moneda.IdMoneda" @(Model.IdMoneda==moneda.IdMoneda?"selected":"") >@moneda.Nombre</option>
                }
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="col-md-4 col-sm-6 control-label"></label>
        <div class="col-md-3 col-sm-6">
        </div>
    </div>
    <fieldset>
        <legend>Costos de viaje:</legend>
    </fieldset>

    <table id="tablaCostosTravelling" class="table table-hover">
        <tr>
            <th>Fecha</th>
            <th>Desde</th>
            <th>Hasta</th>
            <th>Horas</th>
            <th style="width: 30%">Descripcion</th>
            <th>Surveyor</th>
            <th>Subtotal</th>
            <th>Costo flat</th>
            <th>Eliminar</th>
        </tr>
        @foreach(DetalleFacturacion detalle in Model.DetallesFacturacion){
            if (detalle.TipoCosto == Constantes.TipoCostoTravelling)
            {
                int tipoCosto = Constantes.TipoCostoTravelling;
            <tr>
                <td>
                    <input class="form-control customDate reset" onchange="calcularSubtotal(this,1)" maxlength="35" name="fecha" type="text" value="@detalle.Fecha"></td>
                <td>
                    <input class="form-control reset customTime horaIni" onchange="calcularSubtotal(this,1)" name="horaDesde" type="text" value="@detalle.HoraIni"></td>
                <td>
                    <input class="form-control reset customTime horaFin" onchange="calcularSubtotal(this,1)" name="horaHasta" type="text" value="@detalle.HoraFin"></td>
                <td>
                    <input class="form-control reset nHoras" name="nHoras" readonly="readonly" type="text" value="@detalle.HorasSubtotales"></td>
                <td>
                    <textarea class="form-control reset" name="descripcion">@detalle.Descripcion</textarea></td>
                <td>
                    <input class="form-control reset" name="surveyor" type="text" value="@detalle.Surveyor"></td>
                <td>
                    <input class="form-control reset subtotal" name="subtotal" type="text" readonly="readonly" value="@detalle.Costo"></td>
                <td>
                    <input class="form-control reset isflat" name="isflat" onclick="javascript:checkflat(this)"  type="checkbox" value=""></td>
                <td>
                    <a style="vertical-align: top" onclick="javascript:borrarFila(this,1)">
                        <span style="vertical-align: central; line-height: 100%;" class="glyphicon glyphicon-remove"></span>
                    </a>
                    <input name="tipoCosto" type="hidden" value="@tipoCosto">
                </td>
            </tr>
            }
        }
    </table>
    <a style="vertical-align: top" class="linkColumn" href="javascript:nuevaFila(1)">
        <span style="vertical-align: central; line-height: 100%;" class="glyphicon glyphicon-plus-sign"></span>
        <span style="vertical-align: central; line-height: 100%;">Nueva fila</span>
    </a>
    <br />
    

    <div class="form-group">
        <label class="col-md-4 col-sm-6 control-label"></label>
        <div class="col-md-3 col-sm-6">
        </div>
    </div>

    <fieldset>
        <legend>Costos de espera:</legend>
    </fieldset>

    <table id="tablaCostosWaiting" class="table table-hover">
        <tr>
            <th>Fecha</th>
            <th>Desde</th>
            <th>Hasta</th>
            <th>Horas</th>
            <th style="width: 30%">Descripcion</th>
            <th>Surveyor</th>
            <th>Subtotal</th>
            <th>Costo flat</th>
            <th>Eliminar</th>
        </tr>
        @foreach (DetalleFacturacion detalle in Model.DetallesFacturacion)
        {
            if (detalle.TipoCosto == Constantes.TipoCostoWaiting)
            {
                int tipoCosto = Constantes.TipoCostoWaiting;
            <tr>
                <td>
                    <input class="form-control customDate reset" onchange="calcularSubtotal(this,3)" maxlength="35" name="fecha" type="text" value="@detalle.Fecha"></td>
                <td>
                    <input class="form-control reset customTime horaIni" onchange="calcularSubtotal(this,3)" name="horaDesde" type="text" value="@detalle.HoraIni"></td>
                <td>
                    <input class="form-control reset customTime horaFin" onchange   ="calcularSubtotal(this,3)" name="horaHasta" type="text" value="@detalle.HoraFin"></td>
                <td>
                    <input class="form-control reset nHoras" name="nHoras" readonly="readonly" type="text" value="@detalle.HorasSubtotales"></td>
                <td>
                    <textarea class="form-control reset" name="descripcion">@detalle.Descripcion</textarea></td>
                <td>
                    <input class="form-control reset" name="surveyor" type="text" value="@detalle.Surveyor"></td>
                <td>
                    <input class="form-control reset subtotal" name="subtotal" type="text" readonly="readonly" value="@detalle.Costo"></td>
                <td>
                    <input class="form-control reset isflat" name="isflat" onclick="javascript:checkflat(this)"  type="checkbox" value=""></td>
                <td>
                    <a style="vertical-align: top" onclick="javascript:borrarFila(this,1)">
                        <span style="vertical-align: central; line-height: 100%;" class="glyphicon glyphicon-remove"></span>
                    </a>
                    <input name="tipoCosto" type="hidden" value="@tipoCosto">
                </td>
            </tr>
            }
        }
    </table>
    <a style="vertical-align: top" class="linkColumn" href="javascript:nuevaFila(3)">
        <span style="vertical-align: central; line-height: 100%;" class="glyphicon glyphicon-plus-sign"></span>
        <span style="vertical-align: central; line-height: 100%;">Nueva fila</span>
    </a>
    <br />

    <div class="form-group">
        <label class="col-md-4 col-sm-6 control-label"></label>
        <div class="col-md-3 col-sm-6">
        </div>
    </div>

    <fieldset>
        <legend>Costos de trabajo:</legend>
    </fieldset>

    <table id="tablaCostosWorking" class="table table-hover">
        <tr>
            <th>Fecha</th>
            <th>Desde</th>
            <th>Hasta</th>
            <th>Horas</th>
            <th style="width: 30%">Descripcion</th>
            <th>Surveyor</th>
            <th>Subtotal</th>
            <th>Costo flat</th>
            <th>Eliminar</th>
        </tr>
        @foreach (DetalleFacturacion detalle in Model.DetallesFacturacion)
        {
            if (detalle.TipoCosto == Constantes.TipoCostoWorking)
            {
            int tipoCosto = Constantes.TipoCostoWorking;
            <tr>
                <td>
                    <input class="form-control customDate reset" onchange="calcularSubtotal(this,2)" maxlength="35" name="fecha" type="text" value="@detalle.Fecha"></td>
                <td>
                    <input class="form-control reset customTime horaIni" onchange="calcularSubtotal(this,2)" name="horaDesde" type="text" value="@detalle.HoraIni"></td>
                <td>
                    <input class="form-control reset customTime horaFin " onchange   ="calcularSubtotal(this,2)" name="horaHasta" type="text" value="@detalle.HoraFin"></td>
                <td>
                    <input class="form-control reset nHoras" name="nHoras" readonly="readonly" type="text" value="@detalle.HorasSubtotales"></td>
                <td>
                    <textarea class="form-control reset" name="descripcion">@detalle.Descripcion</textarea></td>
                <td>
                    <input class="form-control reset" name="surveyor" type="text" value="@detalle.Surveyor"></td>
                <td>
                    <input class="form-control reset subtotal" name="subtotal" type="text" readonly="readonly" value="@detalle.Costo"></td>
                <td>
                    <input class="form-control reset isflat" name="isflat" onclick="javascript:checkflat(this)"  type="checkbox" value=""></td>
                <td>
                    <a style="vertical-align: top" onclick="javascript:borrarFila(this,1)">
                        <span style="vertical-align: central; line-height: 100%;" class="glyphicon glyphicon-remove"></span>
                    </a>
                    <input name="tipoCosto" type="hidden" value="@tipoCosto">
                </td>
            </tr>
            }
        }
    </table>
    <a style="vertical-align: top" class="linkColumn" href="javascript:nuevaFila(2)">
        <span style="vertical-align: central; line-height: 100%;" class="glyphicon glyphicon-plus-sign"></span>
        <span style="vertical-align: central; line-height: 100%;">Nueva fila</span>
    </a>
    <br />

    <div class="form-group">
        <label class="col-md-4 col-sm-6 control-label"></label>
        <div class="col-md-3 col-sm-6">
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-3 col-sm-6">
            <button type="button" class="btn btn-large btn-primary" onclick="javascript:RegistrarDocumento(document.editForm)">Registrar</button>&nbsp;
            <button type="button" class="btn btn-large" onclick="javascript:history.back();">Atras</button>
        </div>
    </div>


</form>
<!-- / content -->
